﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScriptWeb.control;
using MixScriptWeb.Share;
using MixScript.BLL;
using MixScriptWeb.AppCode.gjips;
using MixScript.BLL.MM;


namespace MixScriptWeb.Jideco.MM
{
    public partial class fPOInq : cCommonWeb // System.Web.UI.Page
    {
        private static DataTable dt;
        private static DataTable dtprint;
        private static SortDirection sd;
        private static cRefGjips oReff;
        private const string stblname = "vw_polist";
        private static string scustid, potyp = "";


        protected void Page_Load(object sender, EventArgs e)
        {
      
            {
                if (!Page.IsPostBack)
                {
                    addFindClickAttribute(this, new MixScriptTB[] { txtCuid }, new string[] { "SRCSUPGJ" });                   
                    txtDate1.CssClass += " ritonli";                    
                    string[] sheadertext = new string[] { "date", "PO No", "Customer", "ID Customer"};
                    string[] sdatavalue = new string[] { "podt", "pono", "bpidnm", "codfbpid" };                    
                    initGvColumn(gvdetail, sheadertext, sdatavalue, new int[] { 0}, "{0:dd-MM-yyyy}");
     
                }
                mn = (MainMenu)this.Master;
                hideStatusBar();              
            }    

        }

        protected void btnFind_Click(object sender, EventArgs e)
        {
            try
            {
                oReff = new cRefGjips(); //new cUserManagement();
                dt = new DataTable();
                Control[] ctl = new Control[] { txtPONum, txtCuid, null, null, txtDate1 };
                cPO oPo = new cPO();
                DateTime tgl1 = new DateTime();
                DateTime tgl2 = new DateTime();

                if(txtDate1.Text!=string.Empty)
                    tgl1=DateTime.Parse(toMDY(txtDate1.Text));

                
                if(txtDate2.Text!=string.Empty)
                    tgl2=DateTime.Parse(toMDY(txtDate2.Text));

                
                
                //if (oReff.getInquiry(ref dt, genInqParam(ctl), stblname, out errMsg))
                if (oPo.getpolist(ref dt, txtPONum.Text, txtCuid.Text, tgl1, tgl2))
                {
                   
                    
                }
                else
                {
                    ShowStatusBar("Record Not Found", msgType.msgError);
                }
                bindGridview(gvdetail, dt);


            }
            catch (Exception)
            {

                throw;
            }
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {

        }

        protected void gvdetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void gvdetail_Sorting(object sender, GridViewSortEventArgs e)
        {

        }

        protected void gvdetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {

                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton lb = (LinkButton)e.Row.FindControl("LinkButton1");
                    string sid = e.Row.Cells[2].Text;
                    string sid2 = e.Row.Cells[4].Text;
                    //string potyp = e.Row.Cells[5].Text;//tetetetetetetfds
                    lb.OnClientClick = "printdn('../print/rptid-2,spono-" + sid + ",suppid-" + sid2 + ",dl.html')";
                    //if (potyp == "1")
                    //{
                    //    Response.Write("window.open('../print/rptid-2,spono-" + sid + ",suppid-" + sid2 + ",dl.html', '_blank');");
                    //}
                    //else if (potyp == "2")
                    //{
                    //    Response.Write("window.open('../print/rptid-3,spono-" + sid + ",suppid-" + sid2 + ",dl.html', '_blank');");
                    //}
                    //else if (potyp == "3")
                    //{
                    //    Response.Write("window.open('../print/rptid-4,spono-" + sid + ",suppid-" + sid2 + ",dl.html', '_blank');");
                    //}
                    //else
                    //{
                    //    Response.Write("window.open('../print/rptid-,spono-" + sid + ",suppid-" + sid2 + ",dl.html', '_blank');");
                    //}
                }


            }
            catch (Exception ex)
            {

                ShowStatusBar(ex.Message);
            }
        }
    }
}